package com.calm.singleton

import android.util.Log

class KDoubleCheckSingleton {
    companion object {
        //原生写法
        val INSTANCE by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            KDoubleCheckSingleton()
        }
        //翻译写法
        @Volatile
        private var INSTANCE1:KDoubleCheckSingleton? = null
        fun getInstance():KDoubleCheckSingleton{
            if(INSTANCE1 == null){
                synchronized(DoubleCheckSingleton::class){
                    if(INSTANCE1 == null){
                        INSTANCE1 = KDoubleCheckSingleton()
                    }
                }
            }
            return INSTANCE1!!
        }
    }
    fun sayHello(name:String){
        Log.e(this::class.java.simpleName,"Hell $name,nice to meet you !")
    }
}